#pragma once
/*!
 * \file 
 * UtilFile.h
 */

/*!
 * \brief class related to "file"
 *
 * class related to "file"
 *
 *	This class is similar to CFile class but has less functionality
 *
 * - header file: UtilFile.h
 * - lib: util.lib
 * - DLL: util.dll
 */

class AFX_EXT_CLASS CUtilFile
{
private:
	HANDLE		m_hFile;

public:
	CUtilFile(void);		/**< constructor 	*/
	~CUtilFile(void);		/**< destructor 	*/


	/*!
	 * Create a file. Although a file exist, it creates always
	 *
	 * @param pFileName A String that is the path to the desired file.
	 * @return if TRUE, the creation was successful. Otherwise FALSE.
	 */
	BOOL Create(TCHAR* pFileName);	
	void Close();	/**< Close the file 	*/
	BOOL isOpen();	/**< Check wheather the file is opened	*/
	/*!
	 * Open the file which already exist
	 *
	 * @param pFileName A String that is the path to the existing file
	 * @param bWrite if TRUE, a file opens with read and write property. if FALSE, a file opens with only read property
	 *
	 * @return if TRUE, the open was successful. Otherwise FALSE.
	 */
	BOOL Open(TCHAR* pFileName, BOOL bWrite=FALSE);
	/*!
	 * Read data into a buffer from the file
	 *
	 * @param pBuffer Pointer to the user-supplied buffer that is to receive the data read from the file.
	 * @param nCount The maximum number of bytes to be read from the file.
	 *
	 * @return if TRUE, the reading was successful. Otherwise FALSE.
	 */
	BOOL Read(VOID *pBuffer, DWORD nCount);
	/*!
	 * Write data from a buffer to the file.
	 *
	 * @param pBuffer Pointer to the user-supplied buffer that contains the data to be written to the file.
	 * @param nCount The number of bytes to be transferred from the buffer.
	 *
	 * @return if TRUE, the writing was successful. Otherwise FALSE.
	 */
	BOOL Write(VOID *pBuffer, DWORD nCount);
	/*!
	 * Repositions the file pointer in an open file
	 *
	 * @param nOffset Number of bytes to move the file pointer. 
	 * Positive values move the file pointer towards the end fo the file; 
	 * negative values move the file pointer towards the start of the file
	 * @param nFrom Position to seek from.
	 *	FILE_BEGIN Seek from the start of the file
	 *	FILE_CURRENT Seek from the current location of the file pointer
	 *	FILE_END Seek from the end of the file
	 *
	 * @return if TRUE, the seeking was successful. Otherwise FALSE.
	 */
	BOOL Seek(__int64 nOffset, DWORD nFrom);
	void Flush();	
	BOOL SetLength(DWORD nLength);
	/*!
	 * Call this function to change the length of the file.
	 *
	 * @param nLength Desired length of the file in bytes.
	 *
	 * @return if TRUE, the length was changed successfully.
	 */
	BOOL SetLength(__int64 nLength);
	/*!
	 * Obtains the current logical length of the file in bytes.
	 *
	 * @return The length of the file.
	 */
	DWORD GetLength();
};
